<template>
  <div>
    <!-- 头部面包屑区域 -->

    <!-- 搜索区域 -->
    <div class="head">
      <el-form :inline="true" :model="formInline">
        <el-form-item label="部门">
          <el-select v-model="formInline.region" placeholder="部门">
            <el-option
              v-for="(item, index) in collegeName"
              :key="index"
              :value="item.college"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- 内容区域 -->
    <div class="content">
      <!-- 表单显示区域 -->
      <div>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column label="日期" width="300">
            <template slot-scope="scope">
              <span style="margin-left: 10px">{{
                scope.row.date | formateData
              }}</span>
            </template>
          </el-table-column>
          <el-table-column label="部门" width="300">
            <template slot-scope="scope">
              <span style="margin-left: 10px">{{ scope.row.collage }}</span>
            </template>
          </el-table-column>
          <el-table-column label="标题" width="300">
            <template slot-scope="scope">
              <span style="margin-left: 10px">{{ scope.row.title }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="mini" @click="handleEdit(scope.row)">
                查看
              </el-button>
            </template>
          </el-table-column>
        </el-table>

        <!-- 公告弹出框 -->
        <el-dialog title="详情" :visible.sync="dialogVisible" width="30%">
          <el-descriptions class="margin-top" :column="1" border>
            <el-descriptions-item>
              <template slot="label"> 所属单位 </template>
              {{ msg.collage }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 发布日期 </template>
              {{ msg.date | formateData }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 公告标题 </template>
              {{ msg.title }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 内容 </template>
              {{ msg.message }}
            </el-descriptions-item>
          </el-descriptions>

          <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="dialogVisible = false"
              >确 定</el-button
            >
          </span>
        </el-dialog>
      </div>
    </div>

    <!-- 分页区域 -->
    <div class="foot">
      <!-- <div>
        <el-pagination background layout="prev, pager, next" :total="1">
        </el-pagination>
      </div> -->
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  // 生命周期函数
  created() {
    this.get_notice();
  },
  data() {
    return {
      msg: {},
      dialogVisible: false,
      formInline: {},
      tableData: [],
    };
  },
  computed: {
    ...mapState(["collegeName"]),
  },
  filters: {
    formateData(time) {
      return new Date(time).toLocaleString();
    },
  },
  methods: {
    // 获取公告信息
    get_notice() {
      this.$http.get("http://127.0.0.1:8080/my/getNotice").then((res) => {
        // console.log(res);
        this.tableData = res.data.data;
      });
    },
    // 搜索按钮
    onSubmit() {
      this.$http
        .post(
          "http://127.0.0.1:8080/teacher/choose_notice",
          this.$qs.stringify(this.formInline)
        )
        .then((res) => {
          this.tableData = res.data.data;
        });
    },
    // 查看按钮
    handleEdit(row) {
      this.dialogVisible = true;
      this.msg = row;
    },
  },
};
</script>

<style lang="less" scoped>
